package syswk.com.tanksgame;

/**
 * 作者：swk
 * 时间：
 * 公司：
 **/
@SuppressWarnings({"all"})
public class Shot implements Runnable {
    private int x;
    private int y;
    private int direct;
    private Boolean isLift = true;
    private int shotSpeed = 100;

    public Shot(int x, int y, int direct, Boolean isLift, int shotSpeed) {
        this.x = x;
        this.y = y;
        this.direct = direct;
        this.isLift = isLift;
        this.shotSpeed = shotSpeed;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public Boolean getLift() {
        return isLift;
    }

    public void setLift(Boolean lift) {
        isLift = lift;
    }

    public int getShotSpeed() {
        return shotSpeed;
    }

    public void setShotSpeed(int shotSpeed) {
        this.shotSpeed = shotSpeed;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (getDirect()) {
                case 0:
                    y -= shotSpeed;
                    break;
                case 1:
                    x += shotSpeed;
                    break;
                case 2:
                    y += shotSpeed;
                    break;
                case 3:
                    x -= shotSpeed;
                    break;
            }
            //System.out.println("X: "+getX()+"   Y: "+ getY());
            if (!(x >= 0 && x <= tankGames.WIDTH && y >= 0 && y <= tankGames.HEIGHT && this.getLift() == true) ) {
                isLift = false;
                break;
            }
        }
    }
}
